﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ElectronicJournal
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void FileUpload1_Unload(object sender, EventArgs e)
        {


        }

        protected void UploadBtn_Click(object sender, EventArgs e)
        {
            string savePath = Server.MapPath("..") + "\\Images\\Header\\";

            if (FileUpload1.HasFile)
            {
                // Get the name of the file to upload.
                string fileName = Server.HtmlEncode(FileUpload1.FileName);


                string extension = System.IO.Path.GetExtension(fileName);

                if ((extension == ".gif") || (extension == ".png"))
                {
                    // Append the name of the file to upload to the path.
                    savePath += fileName;


                    FileUpload1.SaveAs(savePath);
                    try
                    {
                        SqlDataSourceHeaderImage.InsertParameters[0].DefaultValue = "0";
                        SqlDataSourceHeaderImage.InsertParameters[1].DefaultValue = fileName;
                        //SqlDataSource1.InsertParameters[2].DefaultValue = HeightTextBox.Text;
                        //SqlDataSource1.InsertParameters[3].DefaultValue = URLTextBox.Text;
                        //SqlDataSource1.InsertParameters[4].DefaultValue = ImageTextBox.Text;
                        SqlDataSourceHeaderImage.Insert();

    
                        //HeightTextBox.Text = null;
                        //URLTextBox.Text = null;
                        //ImageTextBox.Text = null;
                        UploadStatusLabel.Text = "Файл был успешно загружен";
                    }
                    catch (Exception exp) {
                        UploadStatusLabel.Text = "Файл не сохранен в базу данных";
                    }

                    // Notify the user that their file was successfully uploaded.
                   
                }
                else
                {
                    // Notify the user why their file was not uploaded.
                    UploadStatusLabel.Text = "Файл не был загружен " +
                                             "для загрузки принимаютя только файлы с расширением png gif";
                }

            }

        }
    }
}